package ah.dom;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

import org.apache.xerces.dom.ElementImpl;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class TestDom {

	/**
	 * @author dingdahai
	 * Mar 26, 2010 5:18:16 PM
	 * @param args
	 */
	public static void main(String[] args) {
		new TestDom().test();

	}

	public void test() {
		
		try {
			FileInputStream fis = new FileInputStream("src/dom/test.dat");
			ObjectInputStream ois = new ObjectInputStream(fis);
			ElementImpl root = (ElementImpl)((List)ois.readObject()).get(0);
			
			NodeList nodeList = root.getChildNodes();
			int length = nodeList.getLength();
			String status = null;
			String linkid = null;
			String[] reqids = new String[2];
			for (int i=0; i<length; i++) {
				Node node = nodeList.item(i);
				if (node.getNodeName().equals("status")) {
					status = node.getFirstChild().getNodeValue();
				} else if (node.getNodeName().equals("linkid")) {
					linkid = node.getFirstChild().getNodeValue();
				} else if (node.getNodeName().equals("reqids")) {
					NodeList reqidList = node.getChildNodes();
					reqids[0] = reqidList.item(0).getFirstChild().getNodeValue();
					reqids[1] = reqidList.item(1).getFirstChild().getNodeValue();
				}
			}
			
			System.out.println(status + "," + linkid);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
